#include "MyContactListener.hpp"
#include "Entity.hpp"
#include <cassert>

MyContactListener::MyContactListener():
b2ContactListener()
{
}

void MyContactListener::BeginContact(b2Contact *contact)
{
    Entity *e1 = (Entity*)(contact->GetFixtureA()->GetBody()->GetUserData());
    Entity *e2 = (Entity*)(contact->GetFixtureB()->GetBody()->GetUserData());
    assert(e1 != NULL && e2 != NULL);
    e1->collideWith(*e2);
    e2->collideWith(*e1);
}

void MyContactListener::EndContact(b2Contact *contact)
{
    Entity *e1 = (Entity*)(contact->GetFixtureA()->GetBody()->GetUserData());
    Entity *e2 = (Entity*)(contact->GetFixtureB()->GetBody()->GetUserData());
    assert(e1 != NULL && e2 != NULL);
    e1->endCollideWith(*e2);
    e2->endCollideWith(*e1);
}
